<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../static/css/bootstrap.min.css">
    <link rel="stylesheet" href="../static/css/my_sty.css">
    <style type="text/css">
        body {
            /* url() 为自定义鼠标样式路径 */
            cursor: url(../static/image/pointer.png),auto;
        }
        /* 眼睛样式 */
        #eyes {
            width: 18px;
            position: absolute;
            top: 12px;
            right: 2px;
            float: left;
        }
     </style>
</head>

<body>
    <div id="container" class="shadow p-3 mb-5 bg-white rounded">
        <div id="title">
            <h1 style="text-align: center;margin-bottom: 1rem; margin-top: 0rem;">登录</h1>
        </div>

        <form>
            <!-- 文本框 -->
            <div id="body_middle">
                <!-- 账号框 -->
                <div class="row">
                  <div class="col">
                      <center>
                          <input type="text" class="form-control" id="username" name="username" placeholder="用户名/手机号/邮箱" style="width: 50%; text-align: center;">
                        </center>
                    </div>
                </div>
                <!-- 密码框 -->
                <div class="row">
                    <div class="col">
                        <center>
                            <input type="password" class="form-control" id="password" name="password" placeholder="请输入密码" style="width: 50%; text-align: center">
                            <!-- 功能小眼睛 -->
                            <img src="../static/image/eye-slash.svg" alt="" id="eyes" style="margin-right: 6.6rem; margin-top: 0px; ">
                        </center>
                    </div>
                </div>
            </div>
            
            <!-- 辅助板块 -->
            <div>
                <div class="row">
                    <div class="col">
                        
                    </div>
                </div>
                <!-- 按钮组件 -->
                <div style="text-align: center;">
                    <center></center>
                    <button type="button" class="btn btn-outline-primary" style="width: 14rem;">登录</button> 
                </div>
                <div>
                    <a href="../view/register.html">
                        注册账号
                    </a>
                </div>
            </div>
        </form>
    </div>
    
    <script src="../static/js/jquery-3.5.1.min.js"></script>
    <script src="../static/js/bootstrap.min.js"></script>
    <!-- 登录页输入框焦点逻辑 -->
    <script src="../static/js/login_input_focus.js"></script>
    <!-- 小眼睛——显示隐藏密码实现逻辑 -->
    <script src="../static/js/icon_click.js"></script>
    <!-- 网页特效 -->
    <script src="../static/js/a.js"></script>
    <script src="../static/js/b.js"></script>

    <!-- JQuery跳转代码 -->
    <!-- <script>
        $(document).ready(function(){
            $(".btn").click(function(){
                // window.location.href = "index.html"
                $(location).attr("href", "index.html")
            });
        });
    </script> -->

    <script>
        function register(){
            window.location.href='/register';
        }
        function jump() {
            // 获取表单数据
            let uid = $('#username').val();
            let pwd = $('#password').val();

            // 判断用户名、密码是否为空，为空则提示；不为空则向服务器提交
            if (uid.length > 0 && pwd.length > 0) {
                axios({
                    method: 'post',
                    url: '/loginDone',
                    data: $('#loginForm').serialize(),
                }).then(function (res) {
                    // axios工具下，服务器真正返回的数据在返回对象的data中
                    res = res.data;
                    if (res.code === 200) {
                        window.location.href = '/';
                    } else {
                        alert_fn(res.msg);
                        console.log(res.msg);
                    }
                }).catch((err) => {
                    alert_fn(err);
                    console.log(err);
                });
            } else {
                alert_fn('用户名、密码不能为空');
            }
        }

        // 包装了显示（以及自动隐藏）消息警告的动作
        function alert_fn(msg){
            $('#msgId').text(msg);
            $('.alert').removeClass('invisible');
            setTimeout(() => {
                $('.alert').addClass('invisible');
            }, 3000);
        }
    </script>
</body>
</html>